package com.cbt.cbtBlog.service.impl;

import com.cbt.cbtBlog.bean.BlogInfo;
import com.cbt.cbtBlog.mapper.IBlogInfoMapper;
import com.cbt.cbtBlog.service.IBlogInfoService;
import com.cbt.cbtBlog.util.StringUtil;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class BlogInfoServiceImpl implements IBlogInfoService {
   @Autowired
   private IBlogInfoMapper blogInfoMapper;

   public List<BlogInfo> findAll() {
      return this.blogInfoMapper.findAll();
   }

   public List<BlogInfo> searchContent(Map map) {
      return this.blogInfoMapper.searchContent(map);
   }

   @Transactional
   public BlogInfo getBlogInfo(BlogInfo blog) {
      BlogInfo blogInfo = this.blogInfoMapper.getBlogInfo(blog);
      if (!StringUtil.checkNull(blogInfo)) {
         this.blogInfoMapper.updateView(blogInfo);
      }

      return blogInfo;
   }

   public List<BlogInfo> findByTno(Map map) {
      return this.blogInfoMapper.findByTno(map);
   }

   public int add(BlogInfo blog) {
      blog.setId(StringUtil.getUUid());
      return this.blogInfoMapper.add(blog);
   }

   public List<BlogInfo> getTopBlogs() {
      return this.blogInfoMapper.getTopBlogs();
   }
}
